package demo1;

public class Test {

    public static void main(String[] args) {
        int[] nums = {1};
        int len = removeElement(nums,1);
        for (int i = 0; i < len; i++) {
            System.out.println(nums[i]);
        }

    }

    public static int removeElement(int[] nums, int val) {
        int length = nums.length;
        int j = length - 1;
        int i = 0;
        int tmp = 0;
        while(i < j) {
            while(nums[i] != val && i < j) {
                i++;
            }
            if(nums[i] == val) {
                length--;
            }
            if( i == nums.length - 1) {
                return nums.length;
            }

            while(nums[j] == val && i < j) {
                j--;
                length--;
            }
            if(i != j) {
                tmp = nums[i];
                nums[i] = nums[j];
                nums[j] = tmp;
                i++;
                j--;
            }


        }
        return length;

    }
}
